﻿using System.Collections.Generic;
using Microsoft.Xna.Framework;
using SomeGame.GUI.Widgets;

namespace SomeGame.GUI.WidgetActions {

    public abstract class WidgetAction {

        private readonly IList<WidgetAction> Children = new List<WidgetAction>();
        public WidgetAction Parent;
        public WidgetActionState State = WidgetActionState.Initial;
        public Widget Widget;

        protected WidgetAction(Widget widget, WidgetAction parent, WidgetActionState state) {
            Widget = widget;
            if (parent != null) {
                parent.Children.Add(this);
            }
            Parent = parent;
            State = state;
        }

        public virtual void Update(GameTime gameTime) {
            if (State == WidgetActionState.Done) {
                foreach (WidgetAction widgetAction in Children) {
                    widgetAction.State = WidgetActionState.Ready;
                }
            }
        }

    }

    public enum WidgetActionState {

        Initial,
        Ready,
        Running,
        Done

    }

}